﻿using System;
using System.Reflection;

namespace CoreEx.Common.Reflection
{
    /// <summary>
    /// Extends the <see cref="MethodInfo"/> type.
    /// </summary>
    public static class MethodInfoExtensions
    {
        /// <summary>
        /// Determines whether the specified <paramref name="methodInfo"/>
        /// represents a property get method.
        /// </summary>
        /// <param name="methodInfo">The target <see cref="MethodInfo"/>.</param>
        /// <returns>
        /// 	<c>true</c> if the specified method is a property get method; otherwise, <c>false</c>.
        /// </returns>
        /// <seealso cref="PropertyInfo.GetGetMethod()"/>
        public static bool IsGetter(this MethodInfo methodInfo)
        {
            return methodInfo.IsSpecialName && 
                methodInfo.Name.StartsWith("get_", StringComparison.Ordinal);
        }

        /// <summary>
        /// Determines whether the specified <paramref name="methodInfo"/>
        /// represents a property set method.
        /// </summary>
        /// <param name="methodInfo">The target <see cref="MethodInfo"/>.</param>
        /// <returns>
        /// 	<c>true</c> if the specified method is a property set method; otherwise, <c>false</c>.
        /// </returns>
        /// <seealso cref="PropertyInfo.GetGetMethod()"/>
        public static bool IsSetter(this MethodInfo methodInfo)
        {
            return methodInfo.IsSpecialName &&
                methodInfo.Name.StartsWith("set_", StringComparison.Ordinal);
        }
       
    }
}
